package com.netstar.salesman_90dsp;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.PersistentCookieStore;
import com.netstar.salesman_90dsp.config.SharedPreferencesConfig;

/**
 * 全局应用程序类：用于保存和调用配置及访问网络数据
 * 
 * @author zhangshuai
 * 
 */
public class AppContext extends Application {
	/**
	 * 网络请求对象
	 */
	public AsyncHttpClient asyncHttpClient;
	/**
	 * cookie
	 */
	public PersistentCookieStore asyncHttpClientCookieStore;
	/**
	 * 配置文件对象
	 */
	private SharedPreferences sharedPreferencesDefault;
	/**
	 * 配置文件操作对象
	 */
	private Editor editorDefault;

	@Override
	public void onCreate() {
		asyncHttpClient = new AsyncHttpClient();
		asyncHttpClientCookieStore = new PersistentCookieStore(this);
		asyncHttpClient.setCookieStore(asyncHttpClientCookieStore);
		sharedPreferencesDefault = getSharedPreferences(
				SharedPreferencesConfig.DEFAULT_SP_FILE_NAME,
				Context.MODE_PRIVATE);
		editorDefault = sharedPreferencesDefault.edit();
		super.onCreate();
	}

	/**
	 * 清除cookie
	 */
	public void clearCookie() {
		asyncHttpClientCookieStore.clear();
	}
}
